feat(format): enumerate tracked files via git ls-files in --scope=all#1155
Open
gregmagolan wants to merge 1 commit into
Open
feat(format): enumerate tracked files via git ls-files in --scope=all#1155gregmagolan wants to merge 1 commit into
gregmagolan wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f6b113636
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
thesayyn
approved these changes
May 28, 2026
659fb9c to
ecb46fe
Compare
✨ Aspect Workflows Tasks📅 Sun Jun 28 06:40:33 UTC 2026 ❌ 3 failed tasks
|
8bd55f5 to
7f92d0b
Compare
2ca5698 to
aa1e1a0
Compare
Introduces a new `--scope=tracked` value that enumerates non-gitignored
tracked files via `git ls-files` before passing them to the formatter,
preventing bare formatter binaries like buildifier from visiting gitignored
generated files.
**Scope values** (narrowest → broadest):
- `changed` (default) — files changed vs. merge base
- `tracked` — all git-tracked + untracked-but-not-ignored files via
`git ls-files --cached --others --exclude-standard --full-name`
- `all` — formatter self-discovers files (original behavior unchanged)
**`.gitattributes` filtering** (mirrors rules_lint's `format.sh`):
Files with any of these attributes set to `"true"` or `"set"` are excluded:
- `aspect-format-ignored` — aspect-native escape hatch
- `rules-lint-ignored` — rules_lint compatibility
- `linguist-generated` — GitHub Linguist generated-file marker
- `gitlab-generated` — GitLab equivalent
**Implementation details:**
- `_git_ls_files`: returns repo-relative paths (`--full-name`) so
`--include-pattern` / `--exclude-pattern` (documented as repo-relative)
match correctly; scoped to CWD when invoked from a subdirectory
- `_normalize_files_for_formatter`: converts repo-relative paths to
CWD-relative before spawning the formatter
- `_chunk_files`: splits file lists at 128 000-char batches (same cap as
rules_lint's `format.sh`) to stay under OS arg limits; chunked loop
replaces the single `r.spawn()` call for `scope=tracked`
- `_git_capture_root`: runs git from the repo root with
`core.quotePath=false` so non-ASCII filenames are never C-quoted
- `_apply_pattern_filters`: extracted helper shared by `scope=changed`
and `scope=tracked` branches
- `format_results.axl`: fixed hardcoded `--scope=changed` in the
`no_files_to_format` template message; now uses `{{ scope }}`
**Tests:**
- `format_results_test.axl`: added scenarios 17 (`scope=tracked` with
files) and 18 (`scope=tracked` no-files, exercises the template fix);
loop invariant asserts `--scope=<value>` appears in no-files messages
- All CI platforms (Buildkite, CircleCI, GitLab, GitHub Actions) now
run `--scope=tracked` and `--scope=all` in parallel with the default
`--scope=changed` runs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
aa1e1a0 to
6a07eef
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
--scope=gitto enumerate all non-gitignored tracked files viagit ls-filesbefore invoking the formatter, instead of having the formatter self-discover.--scope=all(formatter self-discovery) is unchanged.What
--scope=gitdoes:git ls-files --cached --others --exclude-standard --full-namefrom the git root, scoped to the invoking directory when run from a subdirectory.gitattributesfiltering (rules-lint-ignored,linguist-generated,gitlab-generated— same attributes as rules_lint)--include-pattern/--exclude-patternagainst repo-relative paths before invoking the formatter (patterns are now effective in scope=all-equivalent mode)format.shcap)Why: Bare formatter binaries (e.g.
@buildifier_prebuilt//buildifier) in--scope=allmode walk the filesystem and may visit gitignored generated files.--scope=gitrestricts the run to files git knows about. Raw formatters that only handle specific file types should pair--scope=gitwith--include-pattern(e.g.--include-pattern='**/*.bzl'for buildifier).Implementation notes:
_chunk_files,_filter_git_attributes,_git_ls_files,_apply_pattern_filters(extracted from duplicate pattern-filter blocks inscope=changedand the newscope=gitbranch)_git_capture_rootruns git from the git root; uses-c core.quotePath=falseso non-ASCII filenames are never C-quoted in output_git_capture/_git_capture_rootboth delegate to_git_capture_into avoid duplicating the process-builder chainlib/format_results.axl: fixed template that hardcoded--scope=changedin the "no files to format" message; now uses the actual scope valueChanges are visible to end-users: yes
Suggested release notes:
--scope=gitforaspect format: enumerates all non-gitignored files viagit ls-files(respecting.gitignoreand.gitattributes) before invoking the formatter. Makes--include-pattern/--exclude-patterneffective in this mode. Bare formatters like buildifier should pair--scope=git --include-pattern='**/*.bzl' --include-pattern='**/BUILD*'to scope to their supported file types.Test plan
aspect format --scope=gitin a repo with gitignored generated BUILD files — they should not be formattedaspect format --scope=git --include-pattern='**/*.bzl'— only .bzl files formattedlinguist-generatedin.gitattributes— should be excluded from--scope=gitaspect format --scope=all— unchanged self-discovery behavioraspect format --scope=gitoutside a git repo — warning emitted, formatter falls back to self-discovery